// FILE: Chip8Keyboard.h by Richard Hughes 03/05/2012
//
// DESC: Defines the Chip 8 Keyboard

#ifndef __chip8keyboard_h__
#define __chip8keyboard_h__

// INCLUDES
#include "IInteruptableDevice.h"

// NAMESPACES
namespace Emulator
{
namespace Chip8
{

// ENUMS
enum Chip8Key
{
	Chip8Key_0 = 0x0,
	Chip8Key_1 = 0x1,
	Chip8Key_2 = 0x2,
	Chip8Key_3 = 0x3,
	Chip8Key_4 = 0x4,
	Chip8Key_5 = 0x5,
	Chip8Key_6 = 0x6,
	Chip8Key_7 = 0x7,
	Chip8Key_8 = 0x8,
	Chip8Key_9 = 0x9,
	Chip8Key_A = 0xA,
	Chip8Key_B = 0xB,
	Chip8Key_C = 0xC,
	Chip8Key_D = 0xD,
	Chip8Key_E = 0xE,
	Chip8Key_F = 0xF,

	Chip8Key_AttachDebugger,
	Chip8Key_DetachDebugger,
	Chip8Key_DebuggerStep,
}; // end Chip8Key

/*************************************************************/
//
// CLASS: Chip8Keyboard
//
// DESC: Defines the Chip 8 Keyboard
//
/*************************************************************/

class Chip8Keyboard : public IInteruptableDevice
{
private:

	int _stepDown;

public:

	Chip8Keyboard()
		: _stepDown(false)
	{
	}
	~Chip8Keyboard()
	{
	}

	virtual bool IsKeyDown(Chip8Key key) = 0;

	virtual bool IsKeyUp(Chip8Key key) = 0;

	Chip8Key WaitUntilKeyPress();

	bool AttachDebugger()
	{
		return this->IsKeyDown(Chip8Key_AttachDebugger);
	}

	bool DetachDebugger()
	{
		return this->IsKeyDown(Chip8Key_DetachDebugger);
	}

	bool DebuggerStep()
	{
		if(_stepDown == 1)
			_stepDown = 2;

		if(_stepDown == 2)
			if(this->IsKeyUp(Chip8Key_DebuggerStep))
				_stepDown = 0;

		if(_stepDown == 0)
			if(this->IsKeyDown(Chip8Key_DebuggerStep))
				_stepDown = 1;

		return _stepDown == 1;
	}
}; // Chip8Keyboard

} // Chip8
} // Emulator

#endif // __iinteruptabledevice_h__

// EOF: Chip8Keyboard.h